<?php
set_time_limit(0);
include_once 'simple_html_dom.php';
function fun($s,$p,$id,$t){

	mysql_query("insert into pronunciation (symbol,`type`,word_id,reference,pronunciation) 
	value(\"".mysql_escape_string($s)."\",".$t.",".$id.",1,\"".$p."\")");

}
mysql_connect("localhost","root","");
mysql_select_db("diandi_danci");
mysql_query("set names utf8");
$result = mysql_query("select * from word where id >6970");
while($row = mysql_fetch_array($result)){
	$url="http://dict.baidu.com/s?wd=".$row['word']."";
	
	$html= file_get_html($url);
	//echo $html;exit;
	if(!$html->find("#pronounce"))continue;
	$base =$html->find("#pronounce",0);
	
	
	if($base->find("span")){//echo 'addd';exit;
		foreach($base->find("span") as $r){
			if (strstr($r->innertext,'英')){
				$s=$r->find('b',0)->innertext;
				$p=$r->find('a',0)->url;
				fun($s,$p,$row['id'],1);
					
			}elseif(strstr($r->innertext,'美')){
				$s=$r->find('b',0)->innertext;
				$p=$r->find('a',0)->url;
				fun($s,$p,$row['id'],2);
			}else{
				$s=$r->find('b',0)->innertext;
				$p=$r->find('a',0)->url;
				fun($s,$p,$row['id'],0);
			}
		}
	}elseif ($base->find("a")){//echo 'nb';exit;
		$p=$base->find('a',0)->url;
		fun("",$p,$row['id']);
	}
	else{
		//echo $base;exit;
	}
	echo $row["id"]."<br>\n";
	
}
